from race.Player import *
import logging.config
from threading import Thread

logging.config.fileConfig('./util/logging.conf')
log = logging.getLogger("example")


class DkTank(Player):

    def on_keyboard_press_son_before_thread(self, key):
        log.debug("on_keyboard_press_son_before_thread 1:进入了函数")
        # 有些按键是直接终止别人的，继续自己的，有些不是这样的，因此要区别对待【排列组合，情况非常多】/【也要超级符合每个职业的操作习惯】
        if key in (
                Key.f1, Key.f2, Key.f3, Key.f4, Key.f5, Key.f6, Key.f7, Key.f8, Key.f9, Key.f10, Key.f11,
                Key.f12):
            pass
        elif key == Key.enter:
            pass
        elif key == Key.space:
            pass
        elif key == Key.alt_l:
            pass
        elif key == Key.ctrl_l:
            pass
        elif key == Key.caps_lock:
            pass
        elif key == Key.shift_l:
            pass
        elif key.char == 'a':
            # 不终止别人，后面让只允许一个线程执行的逻辑来顺序排
            # ★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|★★★★★★|
            # 并行并发执行的折中方案【通过触发其他按键，这样的好处是线程池统一管理了】
            pass
        elif key.char == 'z':
            pass
        elif key.char == 'q':
            pass
        elif key.char == 'w':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'r':
            # 终止掉别人
            # interruptAllByForce()
            pass
        elif key.char == 'g':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'x':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'v':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'h':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'c':
            # 终止掉别人
            self.interruptAllByForce()
        elif key.char == 'e':
            pass
        elif key.char == 's':
            pass
        elif key.char == 'd':
            pass
        elif key.char == 'f':
            pass
        elif key.char == 'b':
            pass
        return

    def a(self):
        self.startScheduler1()  # 调用 CallBackScheduler1
        self.startScheduler2()  # 调用 CallBackScheduler2
        self.startScheduler3()  # 调用 CallBackScheduler3
        self.startScheduler4()  # 调用 CallBackScheduler4
        # self.startScheduler5()  # 调用 CallBackScheduler5
        return

    def CallBackScheduler4(self):
        while self.ui.stopLoop == False:
            self.click(self.kb, '1', 3)
            sleep(0.3)

    def CallBackScheduler1(self):
        while self.ui.stopLoop == False:
            self.click(self.kb, '1', 2)
            sleep(0.1)
            self.click(self.kb, '2', 2)
            sleep(0.1)
            self.click(self.kb, '3', 2)
            sleep(0.1)
            self.click(self.kb, '4', 2)
            sleep(0.1)
            self.click(self.kb, '5', 2)
            sleep(0.1)

    def CallBackScheduler2(self):
        while self.ui.stopLoop == False:
            self.click(self.kb, '5', 2)
            sleep(0.1)
            # self.click(self.kb, '6', 2)
            sleep(0.1)
            self.click(self.kb, '7', 2)
            sleep(0.1)
            self.click(self.kb, '8', 2)
            sleep(0.1)
            # self.click(self.kb, '5', 2)
            # sleep(0.1)

    def CallBackScheduler3(self):
        while self.ui.stopLoop == False:
            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.85, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'n', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.7, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'l', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.6, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', '0', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.5, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 't', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.4, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'k', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

    def x(self):
        for i in range(1, 4):
            self.click(self.kb, '6', 2)
            sleep(0.1)

        # 打断后的继续
        self.click(self.kb, 'a', 1)
        return
